<template>
  <el-dialog
    :title="!doctor.doctorId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="doctor" :rules="dataRule" ref="doctor" @keyup.enter.native="doctorSubmit()" label-width="80px">
    <el-form-item label="用户ID" prop="doctorNumber">
      <el-input v-model="doctor.doctorNumber" placeholder="用户ID"></el-input>
    </el-form-item>
    <el-form-item label="医师姓名" prop="doctorName">
      <el-input v-model="doctor.doctorName" placeholder="医师姓名"></el-input>
    </el-form-item>
    <el-form-item label="医师资格证书图片地址" prop="qualificationCertificate">
      <el-input v-model="doctor.qualificationCertificate" placeholder="医师资格证书图片地址"></el-input>
    </el-form-item>
    <el-form-item label="医师执业证书图片地址" prop="practisingCertificate">
      <el-input v-model="doctor.practisingCertificate" placeholder="医师执业证书图片地址"></el-input>
    </el-form-item>
    <el-form-item label="问诊次数" prop="askTime">
      <el-input v-model="doctor.askTime" placeholder="问诊次数"></el-input>
    </el-form-item>
    <el-form-item label="总收入金额" prop="sumMoney">
      <el-input v-model="doctor.sumMoney" placeholder="总收入金额"></el-input>
    </el-form-item>
    <el-form-item label="好评度" prop="patientGood">
      <el-input v-model="doctor.patientGood" placeholder="好评度"></el-input>
    </el-form-item>
    <el-form-item label="身份证图片地址" prop="idCard">
      <el-input v-model="doctor.idCard" placeholder="身份证图片地址"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="doctor.phone" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="pwd">
      <el-input v-model="doctor.pwd" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item label="隶属医院" prop="affiliatedHospitalId">
      <el-input v-model="doctor.affiliatedHospitalId" placeholder="隶属医院"></el-input>
    </el-form-item>
    <el-form-item label="隶属科室" prop="affiliatedDepartmentId">
      <el-input v-model="doctor.affiliatedDepartmentId" placeholder="隶属科室"></el-input>
    </el-form-item>
    <el-form-item label="医师职称等级 0普通医师 1专家医师 2主任医师（默认值0）" prop="doctorGradeId">
      <el-input v-model="doctor.doctorGradeId" placeholder="医师职称等级 0普通医师 1专家医师 2主任医师（默认值0）"></el-input>
    </el-form-item>
    <el-form-item label="版本" prop="version">
      <el-input v-model="doctor.version" placeholder="版本"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="caeateTime">
      <el-input v-model="doctor.caeateTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="doctor.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="医师问诊状态 0关闭问诊  1开启问诊" prop="doctorEnquiryState">
      <el-input v-model="doctor.doctorEnquiryState" placeholder="医师问诊状态 0关闭问诊  1开启问诊"></el-input>
    </el-form-item>
    <el-form-item label="医师头像" prop="doctorImg">
      <el-input v-model="doctor.doctorImg" placeholder="医师头像"></el-input>
    </el-form-item>
    <el-form-item label="医师审批状态 0待审批 1通过 2未通过" prop="doctorApprovalState">
      <el-input v-model="doctor.doctorApprovalState" placeholder="医师审批状态 0待审批 1通过 2未通过"></el-input>
    </el-form-item>
    <el-form-item label="医师资格证书是否上传 0未上传  1已上传" prop="qualificationCertificateUpState">
      <el-input v-model="doctor.qualificationCertificateUpState" placeholder="医师资格证书是否上传 0未上传  1已上传"></el-input>
    </el-form-item>
    <el-form-item label="医师执业证书是否上传 0未上传  1已上传" prop="practisingCertificateUpState">
      <el-input v-model="doctor.practisingCertificateUpState" placeholder="医师执业证书是否上传 0未上传  1已上传"></el-input>
    </el-form-item>
    <el-form-item label="身份证是否上传 0未上传  1已上传" prop="idCardUpState">
      <el-input v-model="doctor.idCardUpState" placeholder="身份证是否上传 0未上传  1已上传"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="idCardNumber">
      <el-input v-model="doctor.idCardNumber" placeholder="身份证号"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="doctorSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        doctor: {
          doctorId: 0,
          doctorNumber: '',
          doctorName: '',
          qualificationCertificate: '',
          practisingCertificate: '',
          askTime: '',
          sumMoney: '',
          patientGood: '',
          idCard: '',
          phone: '',
          pwd: '',
          affiliatedHospitalId: '',
          affiliatedDepartmentId: '',
          doctorGradeId: '',
          version: '',
          caeateTime: '',
          updateTime: '',
          doctorEnquiryState: '',
          doctorImg: '',
          doctorApprovalState: '',
          qualificationCertificateUpState: '',
          practisingCertificateUpState: '',
          idCardUpState: '',
          idCardNumber: ''
        },
        dataRule: {
          doctorNumber: [
            { required: true, message: '用户ID不能为空', trigger: 'blur' }
          ],
          doctorName: [
            { required: true, message: '医师姓名不能为空', trigger: 'blur' }
          ],
          qualificationCertificate: [
            { required: true, message: '医师资格证书图片地址不能为空', trigger: 'blur' }
          ],
          practisingCertificate: [
            { required: true, message: '医师执业证书图片地址不能为空', trigger: 'blur' }
          ],
          askTime: [
            { required: true, message: '问诊次数不能为空', trigger: 'blur' }
          ],
          sumMoney: [
            { required: true, message: '总收入金额不能为空', trigger: 'blur' }
          ],
          patientGood: [
            { required: true, message: '好评度不能为空', trigger: 'blur' }
          ],
          idCard: [
            { required: true, message: '身份证图片地址不能为空', trigger: 'blur' }
          ],
          phone: [
            { required: true, message: '手机号不能为空', trigger: 'blur' }
          ],
          pwd: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ],
          affiliatedHospitalId: [
            { required: true, message: '隶属医院不能为空', trigger: 'blur' }
          ],
          affiliatedDepartmentId: [
            { required: true, message: '隶属科室不能为空', trigger: 'blur' }
          ],
          doctorGradeId: [
            { required: true, message: '医师职称等级 0普通医师 1专家医师 2主任医师（默认值0）不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本不能为空', trigger: 'blur' }
          ],
          caeateTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          doctorEnquiryState: [
            { required: true, message: '医师问诊状态 0关闭问诊  1开启问诊不能为空', trigger: 'blur' }
          ],
          doctorImg: [
            { required: true, message: '医师头像不能为空', trigger: 'blur' }
          ],
          doctorApprovalState: [
            { required: true, message: '医师审批状态 0待审批 1通过 2未通过不能为空', trigger: 'blur' }
          ],
          qualificationCertificateUpState: [
            { required: true, message: '医师资格证书是否上传 0未上传  1已上传不能为空', trigger: 'blur' }
          ],
          practisingCertificateUpState: [
            { required: true, message: '医师执业证书是否上传 0未上传  1已上传不能为空', trigger: 'blur' }
          ],
          idCardUpState: [
            { required: true, message: '身份证是否上传 0未上传  1已上传不能为空', trigger: 'blur' }
          ],
          idCardNumber: [
            { required: true, message: '身份证号不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.doctor.doctorId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['doctor'].resetFields()
          if (this.doctor.doctorId) {
            this.$http({
              url: this.$http.adornUrl(`/doctor/hospitaldoctor/info/${this.doctor.doctorId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.doctor.doctorNumber = data.hospitalDoctor.doctorNumber
                this.doctor.doctorName = data.hospitalDoctor.doctorName
                this.doctor.qualificationCertificate = data.hospitalDoctor.qualificationCertificate
                this.doctor.practisingCertificate = data.hospitalDoctor.practisingCertificate
                this.doctor.askTime = data.hospitalDoctor.askTime
                this.doctor.sumMoney = data.hospitalDoctor.sumMoney
                this.doctor.patientGood = data.hospitalDoctor.patientGood
                this.doctor.idCard = data.hospitalDoctor.idCard
                this.doctor.phone = data.hospitalDoctor.phone
                this.doctor.pwd = data.hospitalDoctor.pwd
                this.doctor.affiliatedHospitalId = data.hospitalDoctor.affiliatedHospitalId
                this.doctor.affiliatedDepartmentId = data.hospitalDoctor.affiliatedDepartmentId
                this.doctor.doctorGradeId = data.hospitalDoctor.doctorGradeId
                this.doctor.version = data.hospitalDoctor.version
                this.doctor.caeateTime = data.hospitalDoctor.caeateTime
                this.doctor.updateTime = data.hospitalDoctor.updateTime
                this.doctor.doctorEnquiryState = data.hospitalDoctor.doctorEnquiryState
                this.doctor.doctorImg = data.hospitalDoctor.doctorImg
                this.doctor.doctorApprovalState = data.hospitalDoctor.doctorApprovalState
                this.doctor.qualificationCertificateUpState = data.hospitalDoctor.qualificationCertificateUpState
                this.doctor.practisingCertificateUpState = data.hospitalDoctor.practisingCertificateUpState
                this.doctor.idCardUpState = data.hospitalDoctor.idCardUpState
                this.doctor.idCardNumber = data.hospitalDoctor.idCardNumber
              }
            })
          }
        })
      },
      // 表单提交
      doctorSubmit () {
        this.$refs['doctor'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/doctor/hospitaldoctor/${!this.doctor.doctorId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'doctorId': this.doctor.doctorId || undefined,
                'doctorNumber': this.doctor.doctorNumber,
                'doctorName': this.doctor.doctorName,
                'qualificationCertificate': this.doctor.qualificationCertificate,
                'practisingCertificate': this.doctor.practisingCertificate,
                'askTime': this.doctor.askTime,
                'sumMoney': this.doctor.sumMoney,
                'patientGood': this.doctor.patientGood,
                'idCard': this.doctor.idCard,
                'phone': this.doctor.phone,
                'pwd': this.doctor.pwd,
                'affiliatedHospitalId': this.doctor.affiliatedHospitalId,
                'affiliatedDepartmentId': this.doctor.affiliatedDepartmentId,
                'doctorGradeId': this.doctor.doctorGradeId,
                'version': this.doctor.version,
                'caeateTime': this.doctor.caeateTime,
                'updateTime': this.doctor.updateTime,
                'doctorEnquiryState': this.doctor.doctorEnquiryState,
                'doctorImg': this.doctor.doctorImg,
                'doctorApprovalState': this.doctor.doctorApprovalState,
                'qualificationCertificateUpState': this.doctor.qualificationCertificateUpState,
                'practisingCertificateUpState': this.doctor.practisingCertificateUpState,
                'idCardUpState': this.doctor.idCardUpState,
                'idCardNumber': this.doctor.idCardNumber
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
